import java.io.Serializable;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JTextArea;

public class StatusEffect implements Serializable {

	private ArrayList<String> statusMsg = new ArrayList<String>();
	private int startTime;
	private String Name;
	private int duration;
	private GUI gui;
	private String expiryMsg;
	private Random random = new Random();
	private double HP_Penalty;
	private int Endurance_Penalty = 0;
	private int Strength_Penalty = 0;
	private int Intelligence_Penalty = 0;
	private int Agility_Penalty = 0;
	private int Willpower_Penalty = 0;
	
	public StatusEffect(int c, String x, String a, String b, GUI d, String ... messages) {
		Name = x;
		statusMsg.add(a);
		expiryMsg = b;
		duration = c;
		gui = d;
		for (String msg : messages) {
			statusMsg.add(msg);
		}
	}
	
	public String tick(Player player) {
		if (HP_Penalty < 0) {
			player.modifyCurrentHP(HP_Penalty);
			gui.getFeedbackWindow().append(player.getCurrentOpponent().getName() + "'s " + Name + " deals " + Math.abs((int) Math.rint(HP_Penalty)) + " damage.\n");
		}
		return statusMsg.get(random.nextInt(statusMsg.size()));
	}
	
	public String getName() {
		return Name;
	}
	
	public void tickNPC() {
		
	}
	
	public void addPenalty(String a, int b) {
		if (a.equalsIgnoreCase("Strength")) {
			Strength_Penalty = b;
		} else if (a.equalsIgnoreCase("Endurance")) {
			Endurance_Penalty = b;
		} else if (a.equalsIgnoreCase("Agility")) {
			Agility_Penalty = b;
		} else if (a.equalsIgnoreCase("Intelligence")) {
			Intelligence_Penalty = b;
		} else if (a.equalsIgnoreCase("Willpower")) {
			Willpower_Penalty = b;
		} else if (a.equalsIgnoreCase("Health")) {
			HP_Penalty = b;
		}
	}
	
	public String getStatusMsg() {
		int random1 = random.nextInt(statusMsg.size());
		System.out.println(random1);
		return statusMsg.get(random1);

	}
	
	public void setStartTime(int a) {
		startTime = a;
	}
	
	public boolean checkExpired(int turns) {
		boolean result;
			if (duration == 0) {
				if (gui.getPlayer().numActionPoints() < gui.getPlayer().minActionPoints()) {
					return false;
				} else {
					return true;
				}
			} else {
				if ((turns - startTime) >= duration) {
					result = true;
				} else {
					result = false;
				}
			}
		return result;
	}
	
	public String getExpiryMsg() {
		return expiryMsg;
	}
	
	public void addHP_Penalty(double a) {
		HP_Penalty = a;
	}
	
	public int getPenalty(String a) {
		if (a.equalsIgnoreCase("Strength")) {
			return Strength_Penalty;
		} else if (a.equalsIgnoreCase("Endurance")) {
			return Endurance_Penalty;
		} else if (a.equalsIgnoreCase("Agility")) {
			return Agility_Penalty;
		} else if (a.equalsIgnoreCase("Intelligence")) {
			return Intelligence_Penalty;
		} else if (a.equalsIgnoreCase("Willpower")) {
			return Willpower_Penalty;
		} else if (a.equalsIgnoreCase("Health")){
			return (int) Math.rint(HP_Penalty);
		} else {
			return 0;
		}
	}
	
}
